<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>七猫写作 - 作品管理</title>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        /* 基础样式 */
        body {
            font-family: 'Inter', system-ui, sans-serif;
            background-color: #F5F7FA;
            margin: 0;
            padding: 0;
            color: #4E5969;
            font-size: 14px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 16px;
        }

        /* 颜色变量 */
        :root {
            --primary: #165DFF;
            --secondary: #FF7D00;
            --danger: #F53F3F;
            --neutral-100: #F5F7FA;
            --neutral-200: #E5E6EB;
            --neutral-300: #C9CDD4;
            --neutral-400: #86909C;
            --neutral-500: #4E5969;
            --neutral-600: #272E3B;
            --neutral-700: #1D2129;
            --success: #00B42A;
            --error: #F53F3F;
        }

        /* 按钮样式 */
        .btn {
            padding: 8px 16px;
            border-radius: 4px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            border: none;
            text-decoration: none;
            display: inline-block;
        }

        .btn-primary {
            background-color: var(--primary);
            color: white;
        }

        .btn-primary:hover {
            background-color: #0E42D2;
        }

        .btn-secondary {
            background-color: var(--neutral-100);
            color: var(--neutral-500);
        }

        .btn-secondary:hover {
            background-color: var(--neutral-200);
        }

        .btn-danger {
            background-color: var(--danger);
            color: white;
        }

        .btn-danger:hover {
            background-color: #D32F2F;
        }

        /* 输入框样式 */
        .form-input,
        .form-select {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid var(--neutral-300);
            border-radius: 4px;
            font-size: 14px;
            color: var(--neutral-700);
            box-sizing: border-box;
            transition: all 0.2s ease;
        }

        .form-input:focus,
        .form-select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.2);
        }

        /* 头部样式 */
        .header {
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 16px 0;
        }

        .logo {
            display: flex;
            align-items: center;
            font-size: 24px;
            font-weight: 600;
            color: var(--primary);
        }

        .logo img {
            margin-right: 10px;
        }

        /* 作品区域样式 */
        .book-section {
            margin-top: 32px;
        }

        .book-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 24px;
        }

        .title {
            font-size: 20px;
            font-weight: 600;
            color: var(--neutral-600);
        }

        .new-book-btn {
            background-color: var(--primary);
            color: white;
            padding: 8px 16px;
            border-radius: 4px;
            text-decoration: none;
            font-weight: 500;
            transition: background-color 0.2s ease;
        }

        .new-book-btn:hover {
            background-color: #0E42D2;
        }

        /* 表格样式 */
        .book-table {
            width: 100%;
            border-collapse: collapse;
            background-color: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }

        .book-table th,
        .book-table td {
            padding: 16px;
            text-align: left;
            border-bottom: 1px solid var(--neutral-200);
        }

        .book-table th {
            background-color: var(--neutral-100);
            color: var(--neutral-500);
            font-weight: 500;
        }

        .book-table tbody tr:hover {
            background-color: #F9FAFC;
        }

        .book-cover {
            width: 60px;
            height: 80px;
            object-fit: cover;
            border-radius: 4px;
        }

        .operation-btn a {
            display: inline-block;
            margin-right: 10px;
            color: var(--primary);
            text-decoration: none;
            font-size: 14px;
            transition: color 0.2s ease;
        }

        .operation-btn a:hover {
            color: #0E42D2;
        }

        /* 状态标签样式 */
        .status-badge {
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 500;
            display: inline-block;
        }

        .status-badge.serializing {
            background-color: #E8F3FF;
            color: var(--primary);
        }

        .status-badge.completed {
            background-color: #E8FFF3;
            color: var(--success);
        }

        .status-badge.paused {
            background-color: #FFF7E8;
            color: var(--secondary);
        }

        /* 已下架状态样式 */
        .status-badge.taken-down {
            background-color: #FDE6E6;
            color: var(--error);
        }

        /* 模态框样式 */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s ease, visibility 0.3s ease;
        }

        .modal-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        .modal {
            background-color: white;
            border-radius: 8px;
            width: 90%;
            max-width: 500px;
            max-height: 90vh;
            overflow-y: auto;
            transform: translateY(20px);
            transition: transform 0.3s ease;
        }

        .modal-overlay.active .modal {
            transform: translateY(0);
        }

        .modal-header {
            padding: 16px 24px;
            border-bottom: 1px solid var(--neutral-200);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--neutral-600);
        }

        .close-modal {
            background: none;
            border: none;
            font-size: 24px;
            color: var(--neutral-400);
            cursor: pointer;
            transition: color 0.2s ease;
        }

        .close-modal:hover {
            color: var(--neutral-500);
        }

        .modal-body {
            padding: 24px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-size: 14px;
            color: var(--neutral-500);
            font-weight: 500;
        }

        .cover-preview {
            margin-top: 10px;
            display: flex;
            align-items: center;
        }

        .preview-image {
            width: 80px;
            height: 100px;
            object-fit: cover;
            border-radius: 4px;
            margin-right: 12px;
            border: 2px solid transparent;
        }

        .cover-buttons {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 12px;
        }

        .cover-btn {
            padding: 6px 12px;
            border: 1px solid var(--neutral-300);
            border-radius: 4px;
            font-size: 12px;
            color: var(--neutral-500);
            background-color: white;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .cover-btn:hover {
            background-color: var(--neutral-100);
            border-color: var(--neutral-400);
        }

        .cover-btn.primary {
            background-color: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .cover-btn.primary:hover {
            background-color: #0E42D2;
        }

        .modal-footer {
            padding: 16px 24px;
            border-top: 1px solid var(--neutral-200);
            display: flex;
            justify-content: flex-end;
            gap: 12px;
        }

        .small-text {
            font-size: 12px;
            color: var(--neutral-400);
            margin-top: 4px;
        }

        .required {
            color: var(--error);
            margin-left: 4px;
        }

        /* 作者只读样式 */
        .author-readonly {
            background-color: #f5f7fa;
            cursor: not-allowed;
            border-color: #e5e6eb;
        }

        /* 更多操作模态框样式 */
        .action-modal .modal-body {
            padding: 24px;
            text-align: center;
        }

        .action-modal .action-item {
            padding: 12px 0;
            border-bottom: 1px solid var(--neutral-200);
            cursor: pointer;
            transition: background-color 0.2s ease;
        }

        .action-modal .action-item:last-child {
            border-bottom: none;
        }

        .action-modal .action-item:hover {
            background-color: var(--neutral-100);
        }

        .action-icon {
            font-size: 18px;
            margin-right: 10px;
            color: var(--neutral-500);
        }

        .action-text {
            font-size: 14px;
            font-weight: 500;
        }

        /* 禁用的操作项样式 */
        .action-item.disabled {
            cursor: not-allowed;
            opacity: 0.5;
        }

        .action-item.disabled:hover {
            background-color: transparent;
        }

        /* 确认对话框样式 */
        .confirm-dialog {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            border-radius: 8px;
            padding: 24px;
            max-width: 400px;
            width: 90%;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s ease, visibility 0.3s ease;
        }

        .confirm-dialog.active {
            opacity: 1;
            visibility: visible;
        }

        .confirm-title {
            font-size: 18px;
            font-weight: 600;
            color: var(--neutral-600);
            margin-bottom: 12px;
        }

        .confirm-message {
            font-size: 14px;
            color: var(--neutral-500);
            margin-bottom: 24px;
        }

        .confirm-buttons {
            display: flex;
            justify-content: flex-end;
            gap: 12px;
        }

        /* 成功提示样式 */
        .success-toast {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: var(--success);
            color: white;
            padding: 12px 16px;
            border-radius: 4px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            z-index: 1002;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
        }

        .success-toast.active {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        /* 响应式样式 */
        @media (max-width: 768px) {

            .book-table th,
            .book-table td {
                padding: 10px;
                font-size: 14px;
            }

            .operation-btn a {
                display: block;
                margin-bottom: 5px;
            }

            .book-cover {
                width: 40px;
                height: 60px;
            }

            .modal {
                padding: 16px;
            }

            .modal-body {
                padding: 16px 0;
            }
        }
    </style>
    <script src="js/jquery.3.7.1min.js"></script>
</head>

<body>
    <header class="header">
        <div class="container">
            <div class="logo">
                <img src="https://picsum.photos/190/44" alt="七猫写作" class="logo-image">
                <span>七猫写作</span>
            </div>
        </div>
    </header>


    <main class="container book-section">
        <div class="book-header">
            <span class="title">我的作品管理</span>
            <a href="regWorks.html" class="new-book-btn">
                <i class="fa fa-plus-circle mr-2"></i>我要写新书
            </a>
        </div>

        <div class="book-table-container shadow-card rounded-lg overflow-hidden">
            <table class="book-table">
                <thead>
                    <tr>
                        <th>作品编号</th>
                        <th>作品封面</th>
                        <th>作品名称</th>
                        <th>作者</th>
                        <th>作品类型</th>
                        <th>作品状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="books-tbody">
                    <!-- 书籍数据将通过JavaScript动态生成 -->
                    <tr>
                        <td colspan="7" class="text-center py-8">
                            <div class="flex flex-col items-center">
                                <i class="fa fa-book text-4xl text-neutral-300 mb-4"></i>
                                <p class="text-neutral-400">加载中...</p>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </main>


    <!-- 编辑书本信息模态框 -->
    <div class="modal-overlay" id="editBookModal">
        <div class="modal">
            <div class="modal-header">
                <h3 class="modal-title" id="modalTitle">编辑书本信息</h3>
                <button class="close-modal" id="closeModal">
                    <i class="fa fa-times"></i>
                </button>
            </div>
            <div class="modal-body">
                <form id="bookEditForm">
                    <input type="hidden" id="bookId" name="bookId">
                    <input type="hidden" id="bookStatus" name="bookStatus">

                    <div class="form-group">
                        <label for="bookName" class="form-label">
                            作品名称 <span class="required">*</span>
                        </label>
                        <input type="text" id="bookName" name="bookName" class="form-input" required>
                    </div>

                    <div class="form-group">
                        <label for="author" class="form-label">
                            作者 <span class="required">*</span>
                            <span class="small-text" style="display: inline; color: #86909C;">注：作者信息由系统绑定，不可修改</span>
                        </label>
                        <input type="text" id="author" name="author" class="form-input author-readonly" readonly
                            required>
                    </div>

                    <div class="form-group">
                        <label for="bookCover" class="form-label">
                            作品封面
                        </label>
                        <div class="cover-preview">
                            <img src="" alt="封面预览" id="coverPreview" class="preview-image">
                            <div>
                                <label for="uploadCover" class="cover-btn">
                                    <i class="fa fa-upload mr-1"></i>上传封面
                                </label>
                                <input type="file" id="uploadCover" name="uploadCover" accept="image/*" class="hidden">
                            </div>
                        </div>
                        <div class="small-text">支持JPG、PNG格式，建议尺寸200x300px</div>
                    </div>

                    <div class="form-group">
                        <label for="bookType" class="form-label">
                            作品类型 <span class="required">*</span>
                        </label>
                        <div class="form-group">
                            <label for="bigType" class="form-label">
                                大类 <span class="required">*</span>
                            </label>
                            <select id="bigType" name="bigType" class="form-select" required>
                                <option value="">请先选择大类</option>
                                <option value="推理">推理</option>
                                <option value="科幻">科幻</option>
                                <option value="言情">言情</option>
                                <option value="悬疑">悬疑</option>
                                <option value="治愈">治愈</option>
                                <option value="武侠">武侠</option>
                            </select>
                        </div>
                        <div class="form-group" id="smallTypeContainer" style="display: none;">
                            <label for="smallType" class="form-label">
                                小类 <span class="required">*</span>
                            </label>
                            <select id="smallType" name="smallType" class="form-select" required>
                                <option value="">请先选择大类</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" id="cancelEdit">取消</button>
                <button type="submit" form="bookEditForm" class="btn btn-primary">保存修改</button>
            </div>
        </div>
    </div>

    <!-- 更多操作模态框 -->
    <div class="modal-overlay" id="moreActionsModal">
        <div class="modal action-modal">
            <div class="modal-header">
                <h3 class="modal-title">更多操作</h3>
                <button class="close-modal" id="closeMoreActionsModal">
                    <i class="fa fa-times"></i>
                </button>
            </div>
            <div class="modal-body">
                <div class="action-item" id="completeAction">
                    <i class="fa fa-check-circle action-icon" aria-hidden="true"></i>
                    <span class="action-text">完结作品</span>
                </div>
                <div class="action-item" id="takeDownAction">
                    <i class="fa fa-eye-slash action-icon" aria-hidden="true"></i>
                    <span class="action-text">下架作品</span>
                </div>
                <div class="action-item" id="deleteAction">
                    <i class="fa fa-trash action-icon" aria-hidden="true"></i>
                    <span class="action-text">删除作品</span>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" id="cancelMoreActions">取消</button>
            </div>
        </div>
    </div>

    <!-- 确认对话框 -->
    <div class="confirm-dialog" id="confirmDialog">
        <div class="confirm-title" id="confirmTitle">确认操作</div>
        <div class="confirm-message" id="confirmMessage">您确定要执行此操作吗？</div>
        <div class="confirm-buttons">
            <button type="button" class="btn btn-secondary" id="cancelConfirm">取消</button>
            <button type="button" class="btn btn-danger" id="confirmAction">确认</button>
        </div>
    </div>

    <!-- 成功提示 -->
    <div class="success-toast" id="successToast">
        <span id="toastMessage">操作成功！</span>
    </div>


    <script>
        // 作品类型数据 - 大类对应的小类
        const typeData = {
            "推理": ["本格推理", "社会推理", "悬疑推理", "犯罪推理"],
            "科幻": ["硬科幻", "软科幻", "科幻悬疑", "科幻冒险"],
            "言情": ["现代言情", "古代言情", "校园言情", "都市言情"],
            "悬疑": ["心理悬疑", "灵异悬疑", "惊悚悬疑", "侦探悬疑"],
            "治愈": ["暖心治愈", "成长治愈", "情感治愈", "生活治愈"],
            "武侠": ["传统武侠", "新派武侠", "江湖恩怨", "武侠仙侠"]
        };

        // 当前操作的书籍ID、名称和状态
        let currentBookId = null;
        let currentBookName = null;
        let currentBookStatus = null;
        let currentAction = null; // 当前确认的操作类型

        // 获取DOM元素
        const editBookModal = document.getElementById('editBookModal');
        const moreActionsModal = document.getElementById('moreActionsModal');
        const closeModalBtn = document.getElementById('closeModal');
        const cancelEditBtn = document.getElementById('cancelEdit');
        const moreButtons = document.querySelectorAll('.more-btn');
        const closeMoreActionsModalBtn = document.getElementById('closeMoreActionsModal');
        const cancelMoreActionsBtn = document.getElementById('cancelMoreActions');
        const completeAction = document.getElementById('completeAction');
        const takeDownAction = document.getElementById('takeDownAction');
        const deleteAction = document.getElementById('deleteAction');
        const bigTypeSelect = document.getElementById('bigType');
        const smallTypeSelect = document.getElementById('smallType');
        const smallTypeContainer = document.getElementById('smallTypeContainer');
        const coverPreview = document.getElementById('coverPreview');
        const uploadCover = document.getElementById('uploadCover');
        const authorInput = document.getElementById('author');
        const bookStatusInput = document.getElementById('bookStatus');

        // 确认对话框元素
        const confirmDialog = document.getElementById('confirmDialog');
        const confirmTitle = document.getElementById('confirmTitle');
        const confirmMessage = document.getElementById('confirmMessage');
        const cancelConfirmBtn = document.getElementById('cancelConfirm');
        const confirmActionBtn = document.getElementById('confirmAction');

        // 成功提示元素
        const successToast = document.getElementById('successToast');
        const toastMessage = document.getElementById('toastMessage');

        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', function () {
            // 从后端获取书籍数据
            fetchBooks();
            //作家
            a()
        });

        function a() {
            $.ajax({
                type: "GET",
                url: "checkSession.do",
                data: {

                },
                success: function (data) {
                    console.log(data.data);
                    $("#abcd").text(data.data);
                }
            })
        }
        // 从后端获取书籍数据
        function fetchBooks() {
            // 模拟从后端获取JSON数据
            // 实际应用中应该使用fetch或axios等工具从API获取数据
            const booksJson = '[{"id":1,"name":"《白夜行》","author":"东野圭吾","type":"推理","cover":"https://picsum.photos/60/80?random=1","status":"serializing"},{"id":2,"name":"《嫌疑人X的献身》","author":"东野圭吾","type":"推理","cover":"https://picsum.photos/60/80?random=2","status":"completed"},{"id":3,"name":"《解忧杂货店》","author":"东野圭吾","type":"治愈","cover":"https://picsum.photos/60/80?random=3","status":"paused"},{"id":4,"name":"《斗罗大陆》","author":"唐家三少","type":"奇幻","cover":"https://picsum.photos/60/80?random=4","status":"taken-down"}]';

            // 解析JSON数据
            const books = JSON.parse(booksJson);

            // 渲染书籍表格
            renderBooksTable(books);

            // 添加编辑按钮事件监听
            addEditButtonListeners();
        }

        // 渲染书籍表格
        function renderBooksTable(books) {
            const tbody = document.getElementById('books-tbody');
            tbody.innerHTML = ''; // 清空表格

            if (books.length === 0) {
                // 没有书籍数据
                tbody.innerHTML = `
                    <tr>
                        <td colspan="7" class="text-center py-8">
                            <div class="flex flex-col items-center">
                                <i class="fa fa-book text-4xl text-neutral-300 mb-4"></i>
                                <p class="text-neutral-400">暂无作品数据</p>
                            </div>
                        </td>
                    </tr>
                `;
                return;
            }

            // 生成书籍行
            books.forEach(book => {
                const statusClass = getStatusClass(book.status);
                const statusText = getStatusText(book.status);

                const row = document.createElement('tr');
                row.className = 'hover-scale';
                row.innerHTML = `
                    <td>${book.id}</td>
                    <td><img src="${book.cover}" alt="${book.name}封面" class="book-cover"></td>
                    <td>${book.name}</td>
                    <td>${book.author}</td>
                    <td>${book.type}</td>
                    <td><span class="status-badge ${statusClass}">${statusText}</span></td>
                    <td class="operation-btn">
                        <a href="#" class="edit-btn" data-book-id="${book.id}" data-book-name="${book.name}" data-author="${book.author}" data-type="${book.type}" data-cover="${book.cover}" data-status="${book.status}"><i class="fa fa-pencil mr-1"></i>编辑书本信息</a>
                        <a href="test.html" class="update-btn ${book.status === 'completed' || book.status === 'taken-down' ? 'disabled-btn' : ''}" ${book.status === 'completed' || book.status === 'taken-down' ? 'style="opacity: 0.5; cursor: not-allowed;"' : ''}><i class="fa fa-plus mr-1"></i>更新章节</a>
                        <a href="#" class="more-btn" data-book-id="${book.id}" data-book-name="${book.name}" data-status="${book.status}"><i class="fa fa-ellipsis-h mr-1"></i>更多操作</a>
                    </td>
                `;
                tbody.appendChild(row);
            });
        }

        // 获取状态对应的CSS类
        function getStatusClass(status) {
            switch (status) {
                case 'serializing': return 'serializing';
                case 'completed': return 'completed';
                case 'paused': return 'paused';
                case 'taken-down': return 'taken-down';
                default: return '';
            }
        }

        // 获取状态对应的显示文本
        function getStatusText(status) {
            switch (status) {
                case 'serializing': return '连载中';
                case 'completed': return '已完结';
                case 'paused': return '已暂停';
                case 'taken-down': return '已下架';
                default: return status;
            }
        }

        // 添加编辑按钮事件监听
        function addEditButtonListeners() {
            // 清除之前的事件监听器
            const editButtons = document.querySelectorAll('.edit-btn');
            editButtons.forEach(button => {
                // 先移除可能存在的事件监听器
                const newButton = button.cloneNode(true);
                button.parentNode.replaceChild(newButton, button);

                // 添加新的事件监听器
                newButton.addEventListener('click', function (e) {
                    e.preventDefault();
                    const bookId = this.getAttribute('data-book-id');
                    const bookName = this.getAttribute('data-book-name');
                    const author = this.getAttribute('data-author');
                    const bookType = this.getAttribute('data-type');
                    const coverUrl = this.getAttribute('data-cover');
                    const status = this.getAttribute('data-status');

                    // 填充表单数据
                    document.getElementById('bookId').value = bookId;
                    bookStatusInput.value = status;
                    document.getElementById('bookName').value = bookName;
                    authorInput.value = author;
                    coverPreview.src = coverUrl;

                    // 选择对应的作品类型
                    bigTypeSelect.value = bookType;
                    handleBigTypeChange(); // 触发类型变更事件，加载小类

                    // 显示模态框
                    editBookModal.classList.add('active');
                    document.body.style.overflow = 'hidden'; // 防止背景滚动
                });
            });

            // 添加更多操作按钮事件监听
            const moreButtons = document.querySelectorAll('.more-btn');
            moreButtons.forEach(button => {
                // 先移除可能存在的事件监听器
                const newButton = button.cloneNode(true);
                button.parentNode.replaceChild(newButton, button);

                // 添加新的事件监听器
                newButton.addEventListener('click', function (e) {
                    e.preventDefault();
                    currentBookId = this.getAttribute('data-book-id');
                    currentBookName = this.getAttribute('data-book-name');
                    currentBookStatus = this.getAttribute('data-status');

                    // 根据作品状态更新操作按钮状态
                    updateActionButtonsState();

                    // 显示模态框
                    moreActionsModal.classList.add('active');
                    document.body.style.overflow = 'hidden'; // 防止背景滚动
                });
            });

            // 添加更新章节按钮事件监听
            const updateButtons = document.querySelectorAll('.update-btn');
            updateButtons.forEach(button => {
                // 先移除可能存在的事件监听器
                const newButton = button.cloneNode(true);
                button.parentNode.replaceChild(newButton, button);

                // 添加新的事件监听器
                newButton.addEventListener('click', function (e) {
                    // e.preventDefault();
                    if (this.classList.contains('disabled-btn')) {
                        // 已完结或已下架作品不能更新章节
                        showSuccessToast('已完结或已下架作品不能更新章节');
                        return;
                    }

                    // 这里可以添加更新章节的逻辑
                    // alert('跳转到更新章节页面');
                });
            });
        }

        // 更新操作按钮状态
        function updateActionButtonsState() {
            if (currentBookStatus === 'completed') {
                // 已完结，禁用完结按钮
                completeAction.classList.add('disabled');
                completeAction.style.cursor = 'not-allowed';
            } else {
                // 未完结，启用完结按钮
                completeAction.classList.remove('disabled');
                completeAction.style.cursor = 'pointer';
            }

            if (currentBookStatus === 'taken-down') {
                // 已下架，启用删除按钮
                deleteAction.classList.remove('disabled');
                deleteAction.style.cursor = 'pointer';
            } else {
                // 未下架，禁用删除按钮
                deleteAction.classList.add('disabled');
                deleteAction.style.cursor = 'not-allowed';
            }
        }

        // 关闭编辑模态框
        function closeEditModal() {
            editBookModal.classList.remove('active');
            document.body.style.overflow = ''; // 恢复背景滚动

            // 重置表单
            document.getElementById('bookEditForm').reset();
            coverPreview.src = '';
            smallTypeContainer.style.display = 'none';
        }

        // 关闭更多操作模态框
        function closeMoreActionsModal() {
            moreActionsModal.classList.remove('active');
            document.body.style.overflow = ''; // 恢复背景滚动
        }

        // 关闭确认对话框
        function closeConfirmDialog() {
            confirmDialog.classList.remove('active');
            document.body.style.overflow = ''; // 恢复背景滚动
        }

        // 显示成功提示
        function showSuccessToast(message) {
            toastMessage.textContent = message;
            successToast.classList.add('active');

            // 3秒后自动隐藏
            setTimeout(() => {
                successToast.classList.remove('active');
            }, 3000);
        }

        closeModalBtn.addEventListener('click', closeEditModal);
        cancelEditBtn.addEventListener('click', closeEditModal);
        closeMoreActionsModalBtn.addEventListener('click', closeMoreActionsModal);
        cancelMoreActionsBtn.addEventListener('click', closeMoreActionsModal);
        cancelConfirmBtn.addEventListener('click', closeConfirmDialog);

        // 点击模态框外部关闭
        editBookModal.addEventListener('click', function (e) {
            if (e.target === editBookModal) {
                closeEditModal();
            }
        });

        moreActionsModal.addEventListener('click', function (e) {
            if (e.target === moreActionsModal) {
                closeMoreActionsModal();
            }
        });

        confirmDialog.addEventListener('click', function (e) {
            if (e.target === confirmDialog) {
                closeConfirmDialog();
            }
        });

        // 处理大类选择变更
        bigTypeSelect.addEventListener('change', handleBigTypeChange);

        function handleBigTypeChange() {
            const bigType = bigTypeSelect.value;

            // 清空小类选项
            smallTypeSelect.innerHTML = '<option value="">请选择小类</option>';

            if (bigType) {
                // 显示小类容器
                smallTypeContainer.style.display = 'block';

                // 加载对应的小类选项
                typeData[bigType].forEach(smallType => {
                    const option = document.createElement('option');
                    option.value = smallType;
                    option.textContent = smallType;
                    smallTypeSelect.appendChild(option);
                });
            } else {
                // 隐藏小类容器
                smallTypeContainer.style.display = 'none';
            }
        }

        // 上传封面图片
        uploadCover.addEventListener('change', function (e) {
            const file = e.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function (event) {
                    coverPreview.src = event.target.result;
                };
                reader.readAsDataURL(file);
            }
        });

        // 表单提交
        document.getElementById('bookEditForm').addEventListener('submit', function (e) {
            e.preventDefault();

            // 这里可以添加表单验证和提交逻辑
            const bookId = document.getElementById('bookId').value;
            const bookName = document.getElementById('bookName').value;
            const author = authorInput.value; // 直接获取只读输入框的值
            const bigType = bigTypeSelect.value;
            const smallType = smallTypeSelect.value;
            const status = bookStatusInput.value;

            // 模拟提交数据
            console.log('提交编辑数据:', {
                bookId,
                bookName,
                author,
                bigType,
                smallType,
                status
            });

            // 关闭模态框
            closeEditModal();

            // 显示成功提示
            showSuccessToast('书本信息修改成功！');
        });

        // 完结作品功能
        completeAction.addEventListener('click', function () {
            if (currentBookId && currentBookStatus !== 'completed') {
                closeMoreActionsModal();

                // 显示确认对话框
                currentAction = 'complete';
                confirmTitle.textContent = '确认完结';
                confirmMessage.textContent = `确定要完结作品《${currentBookName}》吗？完结后将无法继续更新章节，且无法再进入连载状态。`;
                confirmDialog.classList.add('active');
                document.body.style.overflow = 'hidden';
            }
        });

        // 下架作品功能
        takeDownAction.addEventListener('click', function () {
            if (currentBookId) {
                closeMoreActionsModal();

                // 显示确认对话框
                currentAction = 'takeDown';
                confirmTitle.textContent = '确认下架';
                confirmMessage.textContent = `确定要下架作品《${currentBookName}》吗？下架后作品将不再对读者可见。`;
                confirmDialog.classList.add('active');
                document.body.style.overflow = 'hidden';
            }
        });

        // 删除作品功能
        deleteAction.addEventListener('click', function () {
            if (currentBookId) {
                if (currentBookStatus === 'taken-down') {
                    closeMoreActionsModal();

                    // 显示确认对话框
                    currentAction = 'delete';
                    confirmTitle.textContent = '确认删除';
                    confirmMessage.textContent = `确定要删除作品《${currentBookName}》吗？此操作不可恢复！`;
                    confirmDialog.classList.add('active');
                    document.body.style.overflow = 'hidden';
                } else {
                    // 未下架时的提示
                    showSuccessToast(`作品《${currentBookName}》尚未下架，无法删除。请先下架作品。`);
                }
            }
        });

        // 确认操作
        confirmActionBtn.addEventListener('click', function () {
            if (currentAction === 'complete') {
                // 执行完结操作
                console.log(`完结作品ID: ${currentBookId}, 作品名称: ${currentBookName}`);

                // 关闭确认对话框
                closeConfirmDialog();

                // 显示成功提示
                showSuccessToast(`作品《${currentBookName}》已成功完结！`);

                // 模拟完结后刷新页面（实际应用中可能需要重新加载数据）
                setTimeout(() => {
                    fetchBooks(); // 重新加载书籍数据
                }, 1500);
            } else if (currentAction === 'takeDown') {
                // 执行下架操作
                console.log(`下架作品ID: ${currentBookId}, 作品名称: ${currentBookName}`);

                // 关闭确认对话框
                closeConfirmDialog();

                // 显示成功提示
                showSuccessToast(`作品《${currentBookName}》已成功下架！`);

                // 模拟下架后刷新页面（实际应用中可能需要重新加载数据）
                setTimeout(() => {
                    fetchBooks(); // 重新加载书籍数据
                }, 1500);
            } else if (currentAction === 'delete') {
                // 执行删除操作
                console.log(`删除作品ID: ${currentBookId}, 作品名称: ${currentBookName}`);

                // 关闭确认对话框
                closeConfirmDialog();

                // 显示成功提示
                showSuccessToast(`作品《${currentBookName}》已成功删除！`);

                // 模拟删除后刷新页面（实际应用中可能需要重新加载数据）
                setTimeout(() => {
                    fetchBooks(); // 重新加载书籍数据
                }, 1500);
            }

            // 重置当前操作
            currentAction = null;
        });
    </script>
</body>

</html>